package com.inspur.oss.dao;

import com.inspur.oss.bean.User;
import com.inspur.oss.utils.DBUtils;
import org.junit.Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.List;

public class UserDao {

    public List<User> findUserList() throws Exception{
        Connection connection = DBUtils.getConnection();
        String sql = "select * from tb_user";
       ResultSet resultSet = DBUtils.executePrepareQuery(connection,sql,new Object[]{});
        while(resultSet.next()){
            System.out.println(resultSet.getString("id"));;
        }

        return null;
    }

    public boolean addUser(User user) throws Exception{
        Connection connection = DBUtils.getConnection();
        String sql = "insert into tb_user (id,username,password,email) values(?,?,?,?)";
        Object[] params = {user.getId(),user.getUsername(),user.getPassword(),user.getEmail()};
        return DBUtils.executePrepare(connection,sql,params);
    }

    @Test
    public void test() throws Exception{
        UserDao userDao = new UserDao();
        userDao.findUserList();
    }
}
